package edu.scau.divineplace.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import edu.scau.divineplace.config.global.log.WebLog;
import edu.scau.divineplace.entity.dos.ContentBasicInformationDO;
import edu.scau.divineplace.entity.dos.ContentRoleRelationDO;
import edu.scau.divineplace.entity.enums.ContentTypeEnum;
import edu.scau.divineplace.entity.enums.RoleTypeEnum;
import edu.scau.divineplace.entity.query.content.SuggestionQuery;
import edu.scau.divineplace.entity.query.content.ContentManageQuery;
import edu.scau.divineplace.entity.validate.group.Update;
import edu.scau.divineplace.entity.validate.group.Upload;
import edu.scau.divineplace.entity.vo.content.RoleVO;
import edu.scau.divineplace.entity.vo.content.SuggestionVO;
import edu.scau.divineplace.service.ContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: x1aolone
 * @Date: 2020/12/8 12:55
 */
@Slf4j
@RestController
@CrossOrigin
@Api("Content控制器")
@WebLog("Content控制器")
@Validated
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @ApiOperation("通过内容名和类型，获取输入建议")
    @GetMapping("/list/role")
    public List<RoleVO> listRoles(Long contentId, RoleTypeEnum roleType) {
        return contentService.listRoles(contentId, roleType);
    }

    @ApiOperation("通过内容名和类型，获取输入建议")
    @GetMapping("/suggestion")
    public List<SuggestionVO> getSuggestion (SuggestionQuery query) {
        return contentService.getSuggestion(query);
    }

    @ApiOperation("上传新内容")
    @PostMapping("")
    public void upload (@Validated(Upload.class) @RequestBody ContentManageQuery contentManageQuery) {
        contentService.upload(contentManageQuery);
    }

    @ApiOperation("更新内容")
    @PutMapping("")
    public void update (@Validated(Update.class) @RequestBody ContentManageQuery contentManageQuery) {
        contentService.update(contentManageQuery);
    }

    @ApiOperation("下架内容")
    @DeleteMapping("/{contentId}")
    public void delete (@PathVariable Long contentId) {
        contentService.delete(contentId);
    }

}